package com.pc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pc.pojo.SysResult;
import com.pc.pojo.webPojo;
import com.pc.service.JsoupPageService;
import com.pc.util.log.LogWrite;


/**
 * 	接收准备jsoup的controller类
 * @author ltw
 * @createTime 2018/5/23
 */
@Controller
public class JsoupPageController {
	@Resource
	private JsoupPageService jsoupPageService;

	
	/**
	 * 解析一级目录下的url
	 * @return 将完成状态信息返回
	 */
	@RequestMapping("crawlPage")
	@ResponseBody
	public SysResult CrawlPageUrl() {
		String url = "http://sou.zhaopin.com";
		String select = "#search_right_demo div div a";
		List<webPojo> SecondLevelUrlList = jsoupPageService.querySecondLevelUrl(url, select);
		SysResult result = jsoupPageService.addCityMessage(SecondLevelUrlList);
		return result;
	}

	/**
	 * 添加页码并解析二级目录url
	 * @param 需要解析页面的url
	 * @return 将完成状态信息返回
	 */
	@RequestMapping("addPageNumber")
	@ResponseBody
	public SysResult addPageNumber(@RequestParam String url) {
		LogWrite.warn(JsoupPageController.class, "addPageNumber url =" + url);
		String URL = url.split(",")[1];
		List<webPojo> pNumUrlList = jsoupPageService.queryPageNumber(URL);
		SysResult result = jsoupPageService.queryPositionUrl(pNumUrlList);
		return result;
	}

}
